/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.euitio.jmplayer.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Carballude
 */
public class MPlayerReaderThread implements Runnable {
    
    private BufferedReader input;

    public MPlayerReaderThread(InputStream mplayerInputStream) {
        input = new BufferedReader(new InputStreamReader(mplayerInputStream));
    }

    @Override
    public void run() {
        String line;
        try {
            while((line = input.readLine()) != null){
                if(line.startsWith("ANS_PERCENT_POSITION")){
                    MPlayer.getInstance().updatePositionChangeListeners(Integer.parseInt(line.substring(21)));
                }
                System.out.println(line);
            }
            input.close();
        } catch (IOException ex) {
            Logger.getLogger(MPlayerReaderThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
